package api

import (
	"gitee.com/LangHuaHuachihua/blog-go/apps/blog"
	"gitee.com/LangHuaHuachihua/blog-go/ioc"
	"gitee.com/LangHuaHuachihua/blog-go/protocol/middlewares"
	"github.com/gin-gonic/gin"
)

func NewHandler() *Handler {
	return &Handler{}
}
func (h *Handler) Init() error {
	//断言把any转为需要的对象
	h.svc = ioc.GetController(blog.AppName).(blog.Service)
	return nil
}

type Handler struct {
	svc blog.Service
}

func (h *Handler) Name() string {
	//不同的map不重复----业务都是blog
	return blog.AppName
}

func (h *Handler) Registry(r gin.IRouter) {
	r.GET("/blog/api/v1/blogs", h.QueryBlog)

	//中间件加载
	r.Use(middlewares.Auth)
	r.POST("/blog/api/v1/blogs", h.CreateBlog)
}
func init() {
	ioc.RegistryApiController(&Handler{})
}
